package com.study.myteach.命令模式;


/**
 * @author lk
 * @date 2021/4/30 0030 9:58
 * @description:
 */
public class CalcCommand implements Command {
    private char operator;
    private int operand;
    private Calculator cal;

    public CalcCommand(Calculator cal, char operator, int operand) {
        this.cal = cal;
        this.operator = operator;
        this.operand = operand;
    }

    @Override
    public void execute() {
        this.cal.calc(operator, operand);
    }

    @Override
    public void unExecute() {
        this.cal.calc(undo(operator), operand);
    }

    private char undo(char operator) {
        char obj = ' ';
        switch (operator) {
            case '+':
                obj = '-';
                break;
            case '-':
                obj = '+';
                break;
            case '*':
                obj = '/';
                break;
            case '/':
                obj = '*';
                break;
        }
        return obj;
    }
}
